package org.tamal.classinfo;

import java.io.DataInputStream;
import java.io.IOException;

/**
 * The ElementValuePair data structure.
 * @author Tamal Kanti Nath
 */
public final class ElementValuePair {

    private final ClassInfo cls;
    private int nameIndex;
    private ElementValue value;

    /**
     * Creates ElementValue from DataInputStream.
     * @param in the DataInputStream
     * @param cls The ClassInfo reference
     * @throws IOException exception
     * @see Annotation
     */
    ElementValuePair(DataInputStream in, ClassInfo cls) throws IOException {
        this.cls = cls;
        nameIndex = in.readUnsignedShort();
        value = new ElementValue(in, cls);
    }

    /**
     * Returns element name.
     * @return the element name
     */
    public String getName() {
        return cls.getPool()[nameIndex].toString();
    }

    /**
     * Returns the element value.
     * @return the element value
     */
    public ElementValue getValue() {
        return value;
    }

    @Override
    public String toString() {
        return getName();
    }
}
